//
//  SearchTool.m
//  NursingAssociation
//
//  Created by wsj2015 on 2017/2/20.
//  Copyright © 2017年 wsj2015. All rights reserved.
//

#import "SearchTool.h"

@implementation SearchTool


+ (NSArray *)getRecentSearchKeyWords{
   
    //如果用户未登陆 返回空
   //
    
   return   [[NSUserDefaults standardUserDefaults] arrayForKey:[NSString stringWithFormat:@"HEL_USER_%@",@"测试"]];
    
}

+ (void)addASearchKeyWord:(NSString *)word{

    //如果用户未登陆
//    if (![[HELAppManager userInfo] id]) {
//        return ;
//    }
    NSArray * arr = [self getRecentSearchKeyWords];
     NSMutableArray *newArr = [NSMutableArray arrayWithArray:arr];
    if (arr && arr.count>0) {
        if (![arr containsObject:word]) {
           
            [newArr addObject:word];
            [[NSUserDefaults standardUserDefaults] setObject:newArr forKey:[NSString stringWithFormat:@"HEL_USER_%@",@"测试"]];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
        }
        
    }else{
         [newArr addObject:word];
         [[NSUserDefaults standardUserDefaults] setObject:newArr forKey:[NSString stringWithFormat:@"HEL_USER_%@",@"测试"]];
         [[NSUserDefaults standardUserDefaults] synchronize];
        
    }
  
}
+ (void)removeAwordForIndex:(NSUInteger)index{
   NSArray *resultArr = [self getRecentSearchKeyWords];
    
    if (resultArr && resultArr.count-1 >=index) {
        NSMutableArray *newArr = [NSMutableArray arrayWithArray:resultArr];
        [newArr removeObjectAtIndex:index];
         [[NSUserDefaults standardUserDefaults] setObject:newArr forKey:[NSString stringWithFormat:@"HEL_USER_%@",@"测试"]];
           [[NSUserDefaults standardUserDefaults] synchronize];
        
    }
    
 
}
+ (void)removeAllWord{
   
    [[NSUserDefaults standardUserDefaults] setObject:nil forKey:[NSString stringWithFormat:@"HEL_USER_%@",@"测试"]];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}

@end
